/**
 * 
 */
package com.wcansoft.baseWeb.mybatis_plugin.dao;

import java.util.List;

import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.springframework.stereotype.Component;
@Component("mybatisBaseDAO")
public interface MybatisBaseDAO<T>{
	
	
	
	//根据Query条件查分页记录
	@SelectProvider(type = MybatisSqlProvider.class, method = "listPage")
	List<T> listPage(@Param(value="clazz")Class<?> clazz,@Param(value="query")Query query,@Param(value="currpage")final int currpage,@Param(value="pagesize") final int pagesize);
	
	//根据Query条件查记录
	@SelectProvider(type = MybatisSqlProvider.class, method = "listQuery" )
	List<T> listQuery(@Param(value="clazz")Class<?> clazz,@Param(value="query")Query query);
	

	//根据object赋值条件==查记录
	@SelectProvider(type = MybatisSqlProvider.class, method = "list" )
	List<T> list(T object);

	
	//根据主键值查一条记录
	@SelectProvider(type = MybatisSqlProvider.class, method = "get")
	 T get(@Param(value="clazz") Class<?> clazz,@Param(value="id") Object id);

	//根据query条件查一条记录
	@SelectProvider(type = MybatisSqlProvider.class, method = "getOne")
	T getOne(@Param(value="clazz") Class<?> clazz,@Param(value="query") Query query);

	//根据query条件查记录数
	@SelectProvider(type = MybatisSqlProvider.class, method = "getRowCount")
	Integer getRowCount(@Param(value="clazz") Class<?> clazz,@Param(value="query") Query query);

	//根据query条件查一个字段
	@SelectProvider(type = MybatisSqlProvider.class, method = "getOneRowCol")
	String getOneRowCol(@Param(value="clazz") Class<?> clazz,@Param(value="query") Query query);

	//插入object赋值字段
	@InsertProvider(type = MybatisSqlProvider.class, method = "insert")
	@SelectKey(statement = "SELECT LAST_INSERT_ID() AS id", keyProperty="id", before=false, resultType=Long.class)
	Integer insert(Object object);
	
	//insert插入执行
	@InsertProvider(type = MybatisSqlProvider.class, method = "insertQuery")
	@SelectKey(statement = "SELECT LAST_INSERT_ID() AS id", keyProperty="id", before=false, resultType=Long.class)
	Integer insertQuery(@Param(value="query") Query query);
	
	//根据主键，更新object赋值的字段
	@UpdateProvider(type = MybatisSqlProvider.class, method = "update")
	Integer update(Object object);
	
	//保存对象，id为空insert,id不为空update
	@InsertProvider(type = MybatisSqlProvider.class, method = "save")
	@SelectKey(statement = "SELECT LAST_INSERT_ID() AS id", keyProperty="id", before=false, resultType=Long.class)
	Integer save(Object object);

	//根据条件，更新object赋值的字段
	@UpdateProvider(type = MybatisSqlProvider.class, method = "updateQuery")
	Integer updateQuery(@Param(value="object") Object object,@Param(value="query") Query query);
	@UpdateProvider(type = MybatisSqlProvider.class, method = "updateQuery")
	Integer updateQueryBySql(@Param(value="query") Query query);

	//删除object赋值的字段
	@DeleteProvider(type = MybatisSqlProvider.class, method = "delete")
	Integer delete(Object object);

	//删除Query查詢結果
	@DeleteProvider(type = MybatisSqlProvider.class, method = "deleteQuery")
	Integer deleteQuery(@Param(value="clazz") Class<?> clazz,@Param(value="query") Query query);

}
